package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.service.ManageService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/product")
public class SkuManagerController {
    @Autowired
    private ManageService manageService;

    //保存SkuInfo
    //POST/admin/product/saveSkuInfo
    @ApiOperation("保存SkuInfo")
    @PostMapping("saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        manageService.savaSkuInfo(skuInfo);
        return Result.ok();
    }


    //sku分页列表
    //GET/admin/product/list/{page}/{limit}
    @ApiOperation("sku分页列表")
    @GetMapping("list/{page}/{limit}")
    public Result getList(@PathVariable Long page,
                          @PathVariable Long limit){
        Page<SkuInfo> skuInfoPage = new Page<>();
        IPage<SkuInfo> skuInfoIPage = manageService.getList(skuInfoPage);
        return Result.ok(skuInfoIPage);
    }

    //GET/admin/product/onSale/{skuId}
    @ApiOperation("上架")
    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){

        manageService.onSale(skuId);
        return Result.ok();
    }

    //GET/admin/product/cancelSale/{skuId}
    @ApiOperation("下架")
    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId){

        manageService.cancelSale(skuId);
        return Result.ok();
    }
}
